package com.golang.common.dto;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 接口响应体中的响应头
 * code  message
 * 200	操作成功
 * 400	自定义错误
 * 403	权限不足
 * 404  资源不存在
 * 500  内部错误
 *
 */
public class ResponseHeader {

    private String code;

    private String message;

    public ResponseHeader() {
    }

    public ResponseHeader(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    @Override
    public String toString(){
        ObjectMapper mapper = new ObjectMapper();
        try {
            String jsonString = mapper.writeValueAsString(this);
            return jsonString;
        } catch (JsonProcessingException e) {
            return null;
        }
    }
}
